package cn.etynit.org.service.impl;

import cn.etynit.basic.service.impl.BaseServiceImpl;
import cn.etynit.org.domain.Employee;
import cn.etynit.org.mapper.EmployeeMapper;
import cn.etynit.org.query.EmployeeQuery;
import cn.etynit.org.service.EmployeeService;
import cn.etynit.system.domain.Menu;
import cn.etynit.system.mapper.RoleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class EmployeeServiceImpl extends BaseServiceImpl<Employee> implements EmployeeService {
    @Autowired
    private RoleMapper roleMapper;

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public void add(Employee employee) {
        // 添加员工表
        super.add(employee);
        roleMapper.addMiddle(employee.getId(),employee.getRoles());
    }

    /**
     * 查询角色
     * @return
     */
    @Override
    public List<Employee> role() {
        List<Employee> all = super.findAll();
        return all.stream().filter(al->null == al.getRole()).collect(Collectors.toList());
    }

    @Override
    public Employee selectByLogininfoId(Long id) {
        return employeeMapper.selectByLogininfoId(id);
    }

    /**
     * 根据shopId查询当前店铺所有员工
     * @param shopId
     * @return
     */
    @Override
    public List<Employee> selectByShopId(Long shopId) {
        return employeeMapper.selectByShopId(shopId);
    }
}
